<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue demo08(属性计算)</title>
    <script src="../build/vue.js"></script>
</head>
<body>
<div id="app">
    <div>
        <h2>基本用法</h2>
        <p>a={{a}}, b={{b}}</p>
    </div>
    <div>
        <h2>设置计算属性的setter方法</h2>
        <p>firstName: {{firstName}}</p>
        <p>lastName: {{lastName}}</p>
        <p>fullName: {{fullName}}</p>
    </div>
</div>
<script>
    var vm = new Vue({
        el: '#app',
        data: {
            a: 1,
            firstName: 'xiaobao',
            lastName: 'wei'
        },
        computed: {
            b: function () {
                return this.a + 1;
            },
            fullName: {
                get: function () {
                    return this.firstName + ' ' + this.lastName;
                },
                set: function (newValue) {
                    var names = newValue.split(' ');

                    this.firstName = names[0];
                    this.lastName = names[1];
                }
            }
        }
    });
</script>
</body>
</html>